package com.czy.project.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/********************************************************************
 * @brief mybatisPlus自动填充字段
 * @version 0.1
 * @date 2022年09月06日 22:09
 * @author changziyang
 ********************************************************************/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "create", LocalDateTime.class, LocalDateTime.now()); // 3.3.0(推荐使用)
        this.strictInsertFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now()); // 3.3.0(推荐)
    }
}
